package com.itheima.protocol.curator;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * 创建会话的两种方式
 * String connectString,
 * int sessionTimeoutMs,
 * int connectionTimeoutMs,
 * RetryPolicy retryPolicy
 * ExponentialBackoffRetry  -> 衰减重试
 */

public class createSessionDemo {


    private final static String CONNECTIONSTRING="192.168.1.108:2181";

    public static void main(String[] args) {


        CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(CONNECTIONSTRING, 5000, 5000,
                new ExponentialBackoffRetry(1000, 3));

        //启动建立连接
        curatorFramework.start();

        System.out.println("curatorFramework connect success");


        CuratorFramework curatorFramework1 = CuratorFrameworkFactory.builder().connectString(CONNECTIONSTRING)
                .sessionTimeoutMs(5000)
                .connectionTimeoutMs(5000)
                .retryPolicy(new ExponentialBackoffRetry(1000, 3))
                .namespace("curator")
                .build();
        curatorFramework1.start();
        System.out.println("curatorFramework1 connect success");
    }
}
